package com.omesoft.hksnore.util.handler;

import android.os.Handler;
import android.os.Message;

/**
 * Created by Omesoft on 2017/3/3.
 */

public class MyHandlerUtil {

    private Handler mainHandler;
    private Handler historicalHandler;
    private Handler calcHandler;

    private static MyHandlerUtil instance = null;

    private MyHandlerUtil() {

    }

    public static MyHandlerUtil newInstance() {
        if (instance == null) {
            instance = new MyHandlerUtil();
        }
        return instance;
    }

    public void setMainHandler(Handler mainHandler) {
        this.mainHandler = mainHandler;
    }

    public void setHistoricalHandler(Handler historicalHandler) {
        this.historicalHandler = historicalHandler;
    }

    public void setCalcHandler(Handler calcHandler) {
        this.calcHandler = calcHandler;
    }



    public Handler getMainHandler() {
        return mainHandler;
    }

    public Handler getHistoricalHandler() {
        return historicalHandler;
    }

    public Handler getCalcHandler() {
        return calcHandler;
    }

    /**
     * 公用的发送通知
     *
     * @param flag
     * @param handler
     * @param object
     */
    public static void sendMsg(int flag, Handler handler, Object object) {
        // Log.v("test", "sendMsg(" + flag + ")");
        Message msg = new Message();
        msg.what = flag;
        msg.obj = object;
        if (handler != null) {
            handler.sendMessage(msg);
        }
    }
    public void sendMsg(int flag, Handler handler, float heartbeat,float breathing) {
        // Log.v("test", "sendMsg(" + flag + ")");
        Message msg = new Message();
        msg.what = flag;
        msg.arg1 = (int) heartbeat;
        msg.arg2 = (int) breathing;
        if (handler != null) {
            handler.sendMessage(msg);
        }
    }
    public void sendMsg(Handler handler, int w, Object v) {

        Message msg = new Message();
        msg.what = w;
        msg.obj = v;
        if (handler != null) {
            handler.sendMessage(msg);
        }
    }

    public void sendMsg2(Handler handler, int w, int a, int b) {
        Message msg = new Message();
        msg.what = w;
        msg.arg1 = a;
        msg.arg2 = b;
        if (handler != null) {
            handler.sendMessage(msg);
        }
    }
}
